package com.wjw.cloud.controller;

import com.wjw.cloud.common.api.CommonResult;
import com.wjw.cloud.util.KaptchaUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * @Description: 提供验证码
 * @Author: 王家伟
 * @Date: 2022/2/17
 */
@Controller
@Api(tags = {"KaptchaController 提供验证码"})
@RequestMapping("/KaptchaController")
public class KaptchaController {

    @Autowired
    private KaptchaUtil kaptchaUtil;

    @ApiOperation("创建验证码")
    @RequestMapping(value = "/createImageCode", method = RequestMethod.GET)
    @ResponseBody
    public void createImageCode(HttpServletRequest request, HttpServletResponse response) {

        kaptchaUtil.createImageCode(request, response);

    }

    @ApiOperation("校验验证码")
    @RequestMapping(value = "/checkCode", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult checkCode(@RequestBody Map<String, Object> map) {

        return kaptchaUtil.checkCode(map);

    }

}
